package EX1;

import java.sql.*;

public class demo7 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
        Statement stmt = conn.createStatement();

        String selectsql = "select * from student where name='张三'";

        ResultSet rs = stmt.executeQuery(selectsql);
        while (rs.next()){
            int id=rs.getInt(1);
            String name=rs.getString(2);
            System.out.println("学号："+id+"姓名："+name);
        }

        String insertsql = "insert into student values(8,'赵八')";
        stmt.executeUpdate(insertsql);

        String updatesql = "update student set name='翠花' where id=3";
        stmt.executeUpdate(updatesql);

        String deletesql = "delete from student where name='王五'";
        stmt.executeUpdate(deletesql);

        ResultSet rs2 = stmt.executeQuery("select * from student");
        System.out.println("学生表全部数据：");
        while (rs2.next()){
            int id=rs2.getInt(1);
            String name=rs2.getString(2);
            System.out.println("学号："+id+"姓名："+name);
        }
        rs.close();
        stmt.close();
        conn.close();
    }
}
